﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaygunDiplomacy.Graphics;

namespace RaygunDiplomacy.Graphics
{
   public class DelegateRenderer3D : IRenderer
   {
      Action<TimeSpan, DateTime> update;
      Func<Camera, bool> checkVisibility;
      Action<Camera> render;
      Action dispose;

      public Layers Layer
      {
         get;
         set;
      }

      public DelegateRenderer3D(
         Action<Camera> render,
         Action<TimeSpan, DateTime> update = null,
         Func<Camera, bool> checkVisibility = null,
         Action dispose = null)
      {
         this.update = update;
         this.checkVisibility = checkVisibility;
         this.render = render;
         this.dispose = dispose;
      }

      public void Update(TimeSpan elapsed, DateTime frameNow)
      {
         if (update != null)
         {
            update(elapsed, frameNow);
         }
      }

      public bool CheckVisibility(Camera camera)
      {
         if (checkVisibility != null)
         {
            return checkVisibility(camera);
         }

         return true;
      }

      public void Render(Camera camera)
      {
         if (render != null)
         {
            render(camera);
         }
      }

      public void Dispose()
      {
         if (this.dispose != null)
         {
            this.dispose();
         }
      }
   }
}
